import request from "@/utils/request";
import type { SysDeptDTO, SysDeptFiltDTO, SysDeptVO } from "./sysDeptType";
import type { IdDTO } from "../type/baseType";

enum URL {
    URL_DEPT_BASE = '/dept',
    URL_DEPT_ALL = URL_DEPT_BASE + '/all',
    URL_DEPT_ALL_TREE = URL_DEPT_BASE + '/all/tree'
}

/**
 * 增加Dept
 * @param sysDeptDTO
 * @returns 
 */
export const addDept = (sysDeptDTO: SysDeptDTO):
    Promise<undefined> =>
    request.post(URL.URL_DEPT_BASE, sysDeptDTO)

/**
 * 删除Dept
 * @param id
 * @returns 
 */
export const deleteDept = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_DEPT_BASE}/${id.id}`)

/**
 * 修改Dept
 * @param id
 * @param sysDeptDTO
 * @returns 
 */
export const updateDept = (id: IdDTO, sysDeptDTO: SysDeptDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_DEPT_BASE}/${id.id}`, sysDeptDTO)

/**
 * 查询所有Dept
 * @param isList 返回类型是否需要列表结构，不传递默认为树形结构
 * @param sysDeptFiltDTO
 * @returns 
 */
export const queryDeptAll = (isList?: boolean, sysDeptFiltDTO?: SysDeptFiltDTO):
    Promise<SysDeptVO[]> =>
    request.get(isList ? URL.URL_DEPT_ALL : URL.URL_DEPT_ALL_TREE, {
        params: sysDeptFiltDTO
    })